package com.jic.product.controller.after;

import com.jic.common.base.vo.RestResult;
import com.jic.order.api.OrderGoodsApi;
import com.jic.product.after.api.HotProductApi;
import com.jic.product.after.response.HotProductResponse;
import com.jic.product.model.entity.MHotProduct;
import com.jic.product.service.MHotProductService;
import com.jic.product.store.request.HotProductRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @description: TODO
 * @author: lixuehui
 * @date: 2020/11/28 17:18
 * @Version 1.0
 */
@Slf4j
@Api(tags = "top10商品信息增加")
@RestController
@RequestMapping("/HotProduct")
public class HotProductFegin implements HotProductApi {
    @Autowired
    private MHotProductService service;
    @Resource
    OrderGoodsApi orderGoodsApi;

    @Override
    @ApiOperation(value = "top10商品信息增加")
    @ResponseBody
    @PostMapping("/saveHotProduct")
    public RestResult<Long> saveHotProduct(@RequestBody HotProductRequest request) {
        MHotProduct mHotProduct = new MHotProduct();
        BeanUtils.copyProperties(request, mHotProduct);
        mHotProduct.setId(null);
        mHotProduct.setCreateTime(new Date());
        long flag =   service.saveOrUpdate(mHotProduct);
        return RestResult.success(flag);
    }

    @Override
    public List<com.jic.product.after.response.HotProductResponse> queryHotProduct() {
        //1.查询top10热销商品id
           List<HotProductResponse> hotProductResponses =  service.queryProductListTopTen();
        //2.调用order feign接口，会根据id查询出来

        return null;
    }
}
